package com.xqls.server.dto.send;

import com.xqls.server.dto.SoketCommonDto;
import com.xqls.server.netty.DecoderUtil;
import io.netty.buffer.ByteBuf;
/**
 * 特殊方式采样参数设置
 * @author Administrator
 *
 */
public class SpecialSamplingSetDto extends SoketCommonDto{

	//是否发送过
	private boolean  sendReady=false;

	/**
     * 不采样
     */
    public static final String SAMPLING_NOT="0003";
    
    /**
     * 分瓶采样
     */
    public static final String SAMPLING_BOTTLE="0001";
    
    /**
     * 混合采样
     */
    public static final String SAMPLING_BLEND="0002";
    
    /**
     * 采样方式(不采样,混合采样,分瓶采样)
     */
    private String samplingMethod;
    
    /**
     * 0x01,0x00
     */
    private Integer Unknown;
    
   
    /**
     * 采样瓶数量(默认8瓶)
     */
    private Integer samplingBottles;
    
    /**
     * 单个采样瓶的容量(默认500ml)
     */
    private Integer singleCapacity;
    
    /**
     * 保留
     */
    private Integer retain;
    
    /**
     * 平行样数量
     */
    private Integer simultaneousNumber;
    /**
     * 保留
     */
    private Integer retain1;
    /**
     * 瓶采样时间(默认0x00 0x03)
     * 目前不适用
     */
    private Integer samplingTime;
   
    
    /**
     * 保留
     */
    private Integer retain5;
    
    /**
     * 瓶容量限制(默认为1)
     * 0不限制;1限制
     * 
     */
    private Integer capacityConstraints;
    
    /**
     * 运行时间限制(默认发0)
     * 0不限制;1限制
     */
    private Integer timeLimit;
    /**
     * 假动作功能开启,0关闭,1开启;
     */
    private Integer fakeAction;
    
    /**
     * 保留
     */
    private Integer retain2;
    
    /**
     * 流量累积随机功能开启，0关闭，1开启
     */
    private Integer accumulationFlow;
    /**
     * 短信报警功能开启，0关闭，1开启
     */
    private Integer alarm;
    
    /**
     * 管路传感器功能开启，0关闭，1开启
     */
    private Integer sensor;
    /**
     * 保留
     */
    private Integer retain3;
    /**
     * 保留
     */
    private Integer retain4;



	/**
	 * 采样周期

	 */

	private Integer samplingInterval;

	/**
	 * 采样量
	 */
	private  Integer singleSamplingQuantity;

	public Integer getSingleSamplingQuantity() {
		return singleSamplingQuantity;
	}

	public void setSingleSamplingQuantity(Integer singleSamplingQuantity) {
		this.singleSamplingQuantity = singleSamplingQuantity;
	}

	public Integer getSamplingInterval() {
		return samplingInterval;
	}

	public void setSamplingInterval(Integer samplingInterval) {
		this.samplingInterval = samplingInterval;
	}


	public Integer getLength(){
		return 26;
	}
	public String getCode() {
		return "ca";
	}

	public String getSamplingMethod() {
		return samplingMethod;
	}

	public void setSamplingMethod(String samplingMethod) {
		this.samplingMethod = samplingMethod;
	}

	
	public Integer getRetain() {
		return retain;
	}
	public void setRetain(Integer retain) {
		this.retain = retain;
	}
	public Integer getUnknown() {
		return Unknown;
	}
	public void setUnknown(Integer unknown) {
		Unknown = unknown;
	}
	public Integer getSamplingBottles() {
		return samplingBottles;
	}

	public void setSamplingBottles(Integer samplingBottles) {
		this.samplingBottles = samplingBottles;
	}
	

	public Integer getRetain5() {
		return retain5;
	}
	public void setRetain5(Integer retain5) {
		this.retain5 = retain5;
	}
	public Integer getSingleCapacity() {
		return singleCapacity;
	}

	public void setSingleCapacity(Integer singleCapacity) {
		this.singleCapacity = singleCapacity;
	}

	public Integer getSimultaneousNumber() {
		return simultaneousNumber;
	}

	public void setSimultaneousNumber(Integer simultaneousNumber) {
		this.simultaneousNumber = simultaneousNumber;
	}

	public Integer getSamplingTime() {
		return samplingTime;
	}

	public void setSamplingTime(Integer samplingTime) {
		this.samplingTime = samplingTime;
	}

	public Integer getCapacityConstraints() {
		return capacityConstraints;
	}

	public void setCapacityConstraints(Integer capacityConstraints) {
		this.capacityConstraints = capacityConstraints;
	}

	public Integer getTimeLimit() {
		return timeLimit;
	}

	public void setTimeLimit(Integer timeLimit) {
		this.timeLimit = timeLimit;
	}
	
	
	
	public Integer getRetain1() {
		return retain1;
	}
	public void setRetain1(Integer retain1) {
		this.retain1 = retain1;
	}
	public Integer getFakeAction() {
		return fakeAction;
	}
	public void setFakeAction(Integer fakeAction) {
		this.fakeAction = fakeAction;
	}
	public Integer getRetain2() {
		return retain2;
	}
	public void setRetain2(Integer retain2) {
		this.retain2 = retain2;
	}
	public Integer getAccumulationFlow() {
		return accumulationFlow;
	}
	public void setAccumulationFlow(Integer accumulationFlow) {
		this.accumulationFlow = accumulationFlow;
	}
	public Integer getAlarm() {
		return alarm;
	}
	public void setAlarm(Integer alarm) {
		this.alarm = alarm;
	}
	public Integer getSensor() {
		return sensor;
	}
	public void setSensor(Integer sensor) {
		this.sensor = sensor;
	}
	public Integer getRetain3() {
		return retain3;
	}
	public void setRetain3(Integer retain3) {
		this.retain3 = retain3;
	}
	public Integer getRetain4() {
		return retain4;
	}
	public void setRetain4(Integer retain4) {
		this.retain4 = retain4;
	}
	public void encode( ByteBuf byteBuf){
		if(!sendReady){
		DecoderUtil.integerToBytes(this.getUnknown(),byteBuf,2);
		DecoderUtil.integerToBytes(this.getSamplingBottles(),byteBuf,2);//瓶数，默认8瓶
		DecoderUtil.integerToBytes(this.getSingleCapacity(),byteBuf,4);
		DecoderUtil.integerToBytes(this.getRetain(),byteBuf,2);
		DecoderUtil.integerToBytes(this.getSimultaneousNumber(),byteBuf,2);
		DecoderUtil.integerToBytes(this.getRetain1(),byteBuf,2);
        byteBuf.writeBytes(DecoderUtil.hexStringToBytes(this.getSamplingMethod()));
        DecoderUtil.integerToBytes(this.getSamplingTime(),byteBuf,2);

        //保留,瓶容量限制,运行时间限制,假功能动作开启,保留位,流量累积随机功能开启,短信报警功能开启,管路传感器功能开启,保留位,保留
		byteBuf.writeByte(1);//24保留
        String capacityConstraints=""+this.getCapacityConstraints();
        String timeLimit=""+this.getTimeLimit();
        String fakeAction=""+this.getFakeAction();
        String retain2=""+this.getRetain2();
        String accumulationFlow=""+this.getAccumulationFlow();
        String alarm=""+this.getAlarm();
        String sensor=""+this.getSensor();
        String retain3=""+this.getRetain3();
        String byteStr1="00000"+fakeAction+timeLimit+capacityConstraints;//协议25
        String btyeStr2="00000"+alarm+sensor+accumulationFlow;//协议26
        byteBuf.writeBytes(DecoderUtil.hexStringToBytes(DecoderUtil.binaryString2hexString(byteStr1)));//10
	  	 byteBuf.writeBytes(DecoderUtil.hexStringToBytes(DecoderUtil.binaryString2hexString(btyeStr2)));//10
			byteBuf.writeByte(0);//27保留
        super.encode(byteBuf);
			sendReady=true;
		}else{
			byteBuf.writeBytes(DecoderUtil.hexStringToBytes("0005"));
			byteBuf.writeBytes(DecoderUtil.hexStringToBytes(this.getSamplingMethod()));//8~9
			byteBuf.writeBytes(DecoderUtil.hexStringToBytes("00000000"));//10~13
			DecoderUtil.integerToBytes(this.getSingleSamplingQuantity(),byteBuf,4);//14~17
			DecoderUtil.integerToBytes(this.getSamplingInterval(),byteBuf,4);
			DecoderUtil.integerToBytes(99,byteBuf,2);//大周期
			DecoderUtil.integerToBytes(8888,byteBuf,4);//立即启动
			super.encode(byteBuf);
		}
    }
    

}
